<template>
	<view class="page">
		<view class="price-count-down">
			<view class="price">
				<text class="min">￥</text>
				<text class="max">{{zong}}</text>
			</view>
			<view class="count-down">
				<view class="title">支付剩余时间</view>
				<view class="count">
					<text class="time">{{hour}}</text>
					<text class="dot">:</text>
					<text class="time">{{min}}</text>
					<text class="dot">:</text>
					<text class="time">{{sec}}</text>
				</view>
			</view>
		</view>
		<!-- 支付方式列表 -->
		<view class="pay-way">
			<view class="pay-list">
				<view class="list" v-for="(item,index) in PayList" @click="onPayWay(item,index)" :key="index">
					<view class="pay-type">
						<image :src="item.icon" mode=""></image>
						<text>{{item.name}}</text>
					</view>
					<view class="check">
						<text class="iconfont" :class="PayWay === index ? 'icon-checked action':'icon-check'"></text>
					</view>
				</view>
			</view>
		</view>
		<view class="pay-submit">
			<view class="submit" @click="onSubmit">{{PayPirce}}</view>
		</view>
	</view>
</template>

<script>
	import axios from "axios"
	export default {
		data() {
			return {
				PayList: [{
					icon: '/static/wx_pay.png',
					name: '微信支付 ¥',
				}, {
					icon: '/static/zfb_pay.png',
					name: '支付宝支付 ¥',
				}, {
					icon: '/static/ye_pay.png',
					name: '余额支付 ¥',
				}, ],
				PayWay: 0,
				PayPirce: '',
				CountDown: 1000,
				day: 0,
				hour: 0,
				min: 0,
				sec: 0,
				zong:0,
				orderid:0,
			};
		},
		onLoad() {
			this.CountDownData();
		},
		methods: {
			/**
			 * 支付方式切换点击
			 */
			onPayWay(item, index) {
				this.PayWay = index;
				this.PayPirce = `${item.name}`+this.zong
			},
			/**
			 * 倒计时
			 */
			CountDownData() {
				setTimeout(() => {
					this.CountDown--;
					this.day = parseInt(this.CountDown / (24 * 60 * 60))
					this.hour = parseInt(this.CountDown / (60 * 60) % 24);
					this.min = parseInt(this.CountDown / 60 % 60);
					this.sec = parseInt(this.CountDown % 60);
					if (this.CountDown <= 0) {
						return
					}
					this.CountDownData();
				}, 1000)
			},
			/**
			 * 支付点击
			 */
			onSubmit() {
				axios.request("http://localhost:8089/order/updateOrder/"+this.orderid).then(
					res => {
						if (res.data == true){
							this.$router.push({path:'/pages/PayResult/PayResult',query: { id:this.orderid,zong:this.zong,p:this.PayPirce }});
						}
					}
				)
			},
			onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
				this.zong = option.zong
				this.orderid = option.id
				this.PayPirce =  `微信支付 ¥`+this.zong
				//打印出上个页面传递的参数。传递的是id=1，则获取到的就是option.id
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'CashierDesk.scss';
</style>
